#include <iostream>
#include <vector>
using namespace std;

class st_tree {
	int root = 0;
	int cnt = 1;
	int power = 0;
	vector<int> head, next, to;
	vector<int> deep;
	vector<vector<int>> stjump;

	int log2(int n)
	{
		int ans = 0;
		while ((1 << ans) <= (n >> 1)) {
			ans++;
		}

		return ans;
	}

	void addedge(int u, int v)
	{
		next[cnt] = head[u];
		head[u] = cnt;
		to[cnt++] = v;
	}

	void dfs(int v, int parent)
	{
		deep[v] = deep[parent] + 1;
		stjump[v][0] = parent;
		for (int p = 1; p <= power; p++) {
			stjump[v][p] = stjump[stjump[v][p - 1]][p - 1];
		}

		for (int e = head[v]; e; e = next[e]) {
			if (to[e] != parent) {
				dfs(to[e], v);
			}
		}
	}

	void build()
	{
		dfs(root, root);
	}

	int query(int a, int b)
	{
		if (deep[a] < deep[b]) {
			swap(a, b);
		}

		int k = deep[a] - deep[b], p = 0;
		// while (k) {
		// 	if (k & 1) {
		// 		a = stjump[a][p];
		// 	}
		// 	p++;
		// 	k >>= 1;
		// }
		for(int p = log2(k); p >= 0; p--){
			if(deep[stjump[a][p]] >= deep[b]){
				a = stjump[a][p];
			}
		}
		if (a == b) {
			return a;
		}

		for (int p = power; p >= 0; p--) {
			if (stjump[a][p] != stjump[b][p]) {
				a = stjump[a][p];
				b = stjump[b][p];
			}
		}

		return stjump[a][0];
	}

    public:
	st_tree(int n, int m, int r) : power(log2(n)), root(r), head(n + 1, 0), next(n << 1, 0), to(n << 1, 0), deep(n + 1, 0), stjump(n + 1, vector<int>(power + 1, 0))
	{
		for (int i = 0, u, v; i < n - 1; i++) {
			cin >> u >> v;
			addedge(u, v);
			addedge(v, u);
		}
		build();
		for (int i = 0, a, b; i < m; i++) {
			cin >> a >> b;
			cout << query(a, b) << '\n';
		}
	}
};

int main()
{
	//freopen("/tmp/P3379_4.in", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m, r;
	cin >> n >> m >> r;
	st_tree stree(n, m, r);
	return 0;
}